package com.example.mall.web.controller;

import com.example.mall.domain.TransactionRiskMonitoring;
import com.example.mall.dto.TransactionRiskMonitoringDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.query.TransactionRiskMonitoringQuery;
import com.example.mall.result.JSONResult;
import com.example.mall.service.ITransactionRiskMonitoringService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/transactionRiskMonitoring")
public class TransactionRiskMonitoringController {

    @Autowired
    public ITransactionRiskMonitoringService transactionRiskMonitoringService;

    /**
     * 分页查询交易风险监控表信息
     * @param transactionRiskMonitoringQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询交易风险监控表信息",notes = "分页查询交易风险监控表信息",httpMethod = "GET")
    public JSONResult queryPage(TransactionRiskMonitoringQuery transactionRiskMonitoringQuery){
        PageDTO<TransactionRiskMonitoringDto> transactionRiskMonitoringDtoPageDTO = transactionRiskMonitoringService.queryPage(transactionRiskMonitoringQuery);
        return JSONResult.success("查询成功",transactionRiskMonitoringDtoPageDTO);
    }

    /**
     * 根据id查询交易风险监控表信息
     * @param id
     * @return
     */
    @GetMapping("query/{id}")
    @ApiOperation(value = "根据id查询交易风险监控表信息",notes = "根据id查询交易风险监控表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.MONITORID_NOT_ID);
        }
        TransactionRiskMonitoring transactionRiskMonitoring = transactionRiskMonitoringService.getById(id);
        return JSONResult.success("查询成功",transactionRiskMonitoring);
    }

    /**
     * 根据id查询交易风险监控表信息
     * @param id
     * @return
     */
    @GetMapping("queryTransactionRiskMonitoringById/{id}")
    @ApiOperation(value = "根据id查询交易风险监控表信息",notes = "根据id查询交易风险监控表信息",httpMethod = "GET")
    public JSONResult queryTransactionRiskMonitoringById(@PathVariable("id")Long id){
        //1.根据id查询用户信息
        if (id == null){
            throw new GlobalCustomerException(ErrorEnumCode.MONITORID_NOT_ID);
        }
        TransactionRiskMonitoring transactionRiskMonitoring = transactionRiskMonitoringService.queryTransactionRiskMonitoringById(id);
        return JSONResult.success("查询成功",transactionRiskMonitoring);
    }

    /**
     * 查询全部交易风险监控表信息
     * @param
     * @return
     */
    @GetMapping("queryTransactionRiskMonitoringList")
    @ApiOperation(value = "查询全部交易风险监控表信息",notes = "查询全部交易风险监控表信息",httpMethod = "GET")
    public JSONResult queryTransactionRiskMonitoringList(){
        List<TransactionRiskMonitoring> transactionRiskMonitorings = transactionRiskMonitoringService.queryTransactionRiskMonitoringList();
        return JSONResult.success("查询成功",transactionRiskMonitorings);
    }

    /**
     * 新增交易风险监控表
     * @param transactionRiskMonitoringDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增交易风险监控表",notes = "新增交易风险监控表",httpMethod = "POST")
    public JSONResult insert(@RequestBody TransactionRiskMonitoringDto transactionRiskMonitoringDto){
        transactionRiskMonitoringService.insert(transactionRiskMonitoringDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改交易风险监控表信息
     * @param transactionRiskMonitoringDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改交易风险监控表信息",notes = "修改交易风险监控表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody TransactionRiskMonitoringDto transactionRiskMonitoringDto){
        transactionRiskMonitoringService.update(transactionRiskMonitoringDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除交易风险监控表信息
     * @param id
     * @return
     */
    @PostMapping("delete/{id}")
    @ApiOperation(value = "删除交易风险监控表信息",notes = "删除交易风险监控表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("activitiesProductId") Long id) {
        transactionRiskMonitoringService.delete(id);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除交易风险监控表信息
     * @param ids
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除交易风险监控表信息",notes = "批量删除交易风险监控表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> ids) {
        transactionRiskMonitoringService.deleteBatch(ids);
        return JSONResult.success("批量删除成功");
    }
}
